#extension GL_OES_EGL_image_external : require
precision mediump float;
uniform sampler2D uTextureSampler;
varying vec2 vTextureCoord;
const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);

uniform lowp float saturation;
uniform lowp float brightness;
uniform lowp float exposure;
uniform lowp float contrast;

void main()
{
    //纹理颜色
    vec4 vTextureColor = texture2D(uTextureSampler, vTextureCoord);

    //饱和度
    lowp float luminance = dot(vTextureColor.rgb, luminanceWeighting);
    lowp vec3 greyScaleColor = vec3(luminance);
    vec4 saturationColor = vec4(mix(greyScaleColor, vTextureColor.rgb, saturation), vTextureColor.w);
    vTextureColor = saturationColor;

    //亮度
    vec4 brightnessColor = vec4((vTextureColor.rgb + vec3(brightness)), vTextureColor.w);
    vTextureColor = brightnessColor;

    //曝光度
    vec4 exposureColor = vec4(vTextureColor.rgb * pow(2.0, exposure), vTextureColor.w);
    vTextureColor = exposureColor;

    //对比度
    vec4 contrastColor = vec4(((vTextureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), vTextureColor.w);
    vTextureColor = contrastColor;

    gl_FragColor = vTextureColor;
}